//
//  ViewController.m
//  28---UIViewAnimation
//
//  Created by 冀永金 on 16/8/22.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "ViewController.h"
#import "UIView+Frame.h"
@interface ViewController ()
@property (nonatomic, strong) UIView *animationView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.animationView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0,100)];
    [self.view addSubview:_animationView];
    _animationView.backgroundColor = [UIColor cyanColor];
    // 1.UIView Animation
    
    // 1>开始动画
    [UIView beginAnimations:nil context:NULL];
    //2> 动画延时
    [UIView setAnimationDelay:1];
    //[UIView setAnimationStartDate:[NSDate dateWithTimeIntervalSinceNow:1]];
    
    //动画重复次数
    //[UIView setAnimationRepeatCount:2.5];
    
    //自动翻转 来回算一次
    
    //[UIView setAnimationRepeatAutoreverses:YES];
    // 忽略动画效果
   // [UIView setAnimationsEnabled:NO];
    
    //3> 设置动画持续的时间
    //[UIView setAnimationDuration:10];
    //4>设置动画曲线，如何进行动画
  [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
   // 5>动画的改变
    _animationView.yj_width = [UIScreen mainScreen].bounds.size.width;
      // _animationView.jy_height = [UIScreen mainScreen].bounds.size.height;
       // 6>动画的代理  不签定代理，代理方法不执行（默认为你不签代理）
    //
    [UIView setAnimationDelegate:self];
    // 将要开始
    [UIView setAnimationWillStartSelector:@selector(animationWillStart:context:)];
    // 已将结束
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
     // 6>
    [UIView commitAnimations];
    // 结束动画  执行该动画
    //2.UIViewAnimationBlock
    //1> UIViewBlockAnimation
    /**
     *  参数1：持续时间
     参数2：block 需要执行的动画效果
     */
   // [UIView animateWithDuration:2 animations:^{
       // _animationView.yj_x = 300;
    //}];
    // 2>
//    [UIView animateWithDuration:3 animations:^{
//        _animationView.yj_x = 300;
//
//    } completion:^(BOOL finished) {
//        NSLog(@"动画完成");
    //}];
    
    [UIView animateWithDuration:10 delay:2 options:UIViewAnimationOptionAutoreverse  animations:^{
        _animationView.yj_x = 300;
    } completion:^(BOOL finished) {
        NSLog(@"动画完成 ");
    }];
    
}
-(void)animationWillStart:(NSString *)animationID context:(void *)context {
    NSLog(@"动画开始");
}
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    NSLog(@"动画结束");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
